/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.chart;

import com.bean.chart.iterfaces.AbstractChartLegend;
import com.bean.chart.iterfaces.AbstractChartTitle;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.beans.*;
import java.io.Serializable;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author sammael
 */
public class ChartLabel extends JComponent implements AbstractChartTitle, Serializable {
    
    public static final String PROP_FOREGROUND="foreground_property";
    public static final String PROP_BACKGROUND="background_property";
    public static final String PROP_LABEL= "label_property";
    
    private String label = "Test Label";
    private Color foreground = Color.DARK_GRAY;
    private Color background = Color.LIGHT_GRAY;
    private PropertyChangeSupport propertySupport;
    private JLabel lbl = new JLabel(label);
    
    public ChartLabel() {
        propertySupport = new PropertyChangeSupport(this);
        this.setLayout(new BorderLayout());
        lbl.setHorizontalAlignment(JLabel.CENTER);
        lbl.setVerticalAlignment(JLabel.CENTER);
        lbl.setBackground(background);
        lbl.setForeground(foreground);
        this.setOpaque(false);
        add(lbl);
    }
   
    @Override
    public void setTitleText(String text) {
        String old = this.label;
        this.label = text;
        lbl.setText(this.label);
        propertySupport.firePropertyChange(PROP_LABEL, old, text);
        repaint();
    }

    @Override
    public String getTitleText() {
        return label;
    }

    @Override
    public void setTitleBackground(Color color) {
        Color old = this.background;
        background = color;
        propertySupport.firePropertyChange(PROP_BACKGROUND, old, background);
        lbl.setBackground(background);
        setBackground(background);
        repaint();
        validate();
    }

    @Override
    public Color getTitleBackground() {
        return background;
    }

    @Override
    public void setTitleForeground(Color color) {
        Color old = this.foreground;
        foreground = color;
        propertySupport.firePropertyChange(PROP_FOREGROUND, old, foreground);
        lbl.setForeground(foreground);
        repaint();
    }

    @Override
    public Color getTitleForeground() {
        return foreground;
    }

    @Override
    public void setFont(Font font) {
        super.setFont(font);
        lbl.setFont(font);
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(background);
        g.fillRect(0, 0, getSize().width, getSize().height);
        super.paintComponent(g);
    }
    
   
    
}
